package com.chezhujie.www.service;

import com.chezhujie.www.core.exception.ClassCheckException;
import com.chezhujie.www.core.page.Pagination;
import com.chezhujie.www.domain.Czjromotion;
import com.chezhujie.www.domain.vo.FestSelectVO;
import com.chezhujie.www.persistence.CzjromotionMapper;
import com.chezhujie.www.utils.UUIDUtils;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 扫描-活动/奖品统计
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjromotionService extends BaseService<Czjromotion>{
    @Autowired
    private CzjromotionMapper czjromotionMapper;

    @Autowired
    public void setBaseMapper(CzjromotionMapper czjromotionMapper) {
        this.baseMapper = czjromotionMapper;
    }


    public void checkEntity(Czjromotion czjromotion) throws ClassCheckException {
        if(czjromotion.getRomotionId()!=null&&czjromotion.getRomotionId().length()>19){
            throw new ClassCheckException("扫描-活动/奖品统计主键不能超过19个字符");
        }
        if(czjromotion.getType()!=null&&czjromotion.getType().length()>2){
            throw new ClassCheckException("扫描-活动/奖品统计核销类型不能超过2个字符");
        }
        if(czjromotion.getRemoname()!=null&&czjromotion.getRemoname().length()>19){
            throw new ClassCheckException("扫描-活动/奖品统计核销人姓名不能超过19个字符");
        }
        if(czjromotion.getRemophone()!=null&&czjromotion.getRemophone().length()>19){
            throw new ClassCheckException("扫描-活动/奖品统计核销人手机不能超过19个字符");
        }
        if(czjromotion.getRegion()!=null&&czjromotion.getRegion().length()>20){
            throw new ClassCheckException("扫描-活动/奖品统计核销人地区不能超过20个字符");
        }
        if(czjromotion.getUserinfoId()!=null&&czjromotion.getUserinfoId().length()>19){
            throw new ClassCheckException("扫描-活动/奖品统计用户id不能超过19个字符");
        }
        if(czjromotion.getTelephone()!=null&&czjromotion.getTelephone().length()>50){
            throw new ClassCheckException("扫描-活动/奖品统计用户手机不能超过50个字符");
        }
        if(czjromotion.getNickname()!=null&&czjromotion.getNickname().length()>50){
            throw new ClassCheckException("扫描-活动/奖品统计用户昵称不能超过50个字符");
        }
        if(czjromotion.getActivityId()!=null&&czjromotion.getActivityId().length()>50){
            throw new ClassCheckException("扫描-活动/奖品统计订单Id不能超过50个字符");
        }
        if(czjromotion.getActivityNum()!=null&&czjromotion.getActivityNum().length()>19){
            throw new ClassCheckException("扫描-活动/奖品统计订单编号不能超过19个字符");
        }
        if(czjromotion.getFestId()!=null&&czjromotion.getFestId().length()>50){
            throw new ClassCheckException("扫描-活动/奖品统计活动id不能超过50个字符");
        }
        if(czjromotion.getFestName()!=null&&czjromotion.getFestName().length()>50){
            throw new ClassCheckException("扫描-活动/奖品统计活动名称不能超过50个字符");
        }
    }
    public void checkListEntity(List<Czjromotion> listCzjromotion) throws ClassCheckException {

        for (Czjromotion czjromotion : listCzjromotion) {
            checkEntity(czjromotion);
        }

    }


	public Integer getSumNumByActId(String activityId) {
		return czjromotionMapper.getSumNumByActId(activityId);
	}


	public List<FestSelectVO> getFestSelect() {
		return czjromotionMapper.getFestSelect();
	}


	public Pagination listByPhone(int pageNo, int pageSize,
			Map<String, Object> params, ModelMap model) {
	
		 Pagination pagination = new Pagination();
	        pagination.setPageNo(pageNo);
	        pagination.setPageSize(pageSize);
	        params.putAll(pagination.toMap());
	        int count = czjromotionMapper.getRowsByPhone(params);
	        List<Map<String, Object>> list = czjromotionMapper.getListByPhone(params);
	        pagination.setTotalCount(count);
	        pagination.setList(list);
	        return pagination;
		
	}
	
	
}
